package cn.edu.nwpu.warehousemanagement.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 通用响应结果
 *
 * @author Loadstar
 * @version 1.0
 **/
@NoArgsConstructor
@AllArgsConstructor
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    //带响应数据返回操作成功响应结果
    public static <E> Result<E> success(E data) {
        return new Result<>(200, "success", data);
    }

    //不带响应数据返回操作成功响应结果
    public static <E> Result<E> success() {
        return new Result<>(200, "success", null);
    }

    //返回操作错误响应结果
    public static <E> Result<E> error(String message) {
        return new Result<>(400, message, null);
    }
}